<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring Boot 内嵌Web容器指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
        }
        .container-icon {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 60px;
            height: 60px;
            border-radius: 50%;
            margin-bottom: 1rem;
            color: white;
            font-size: 1.5rem;
        }
        .code-block {
            background: #2d3748;
            color: #e2e8f0;
            border-radius: 0.375rem;
            padding: 1rem;
            overflow-x: auto;
            font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
        }
        .code-block .xml {
            color: #f8fafc;
        }
        .code-block .tag {
            color: #f56565;
        }
        .code-block .attr {
            color: #38b2ac;
        }
        .code-block .val {
            color: #4299e1;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero text-white py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-4">Spring Boot 内嵌Web容器指南</h1>
            <p class="text-xl md:text-2xl mb-8">探索Tomcat、Jetty和Undertow的选择与配置</p>
            <div class="flex justify-center">
                <div class="w-full md:w-2/3 lg:w-1/2 bg-white bg-opacity-20 rounded-lg p-6 backdrop-blur-sm">
                    <p class="text-lg">Spring Boot支持多种内嵌Web容器，每种都有独特优势。本文将深入分析Apache Tomcat、Jetty和Undertow的特点，帮助您为项目选择最佳解决方案。</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Container Comparison -->
    <section class="py-16">
        <div class="container mx-auto px-6">
            <h2 class="text-3xl font-bold text-center mb-12">三大内嵌Web容器对比</h2>
            
            <div class="grid grid-cols-1 md:grid-cols-3 gap-8">
                <!-- Tomcat Card -->
                <div class="card bg-white rounded-lg p-8">
                    <div class="container-icon bg-gradient-to-r from-red-500 to-orange-500">
                        <i class="fas fa-server"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4">Apache Tomcat</h3>
                    <p class="text-gray-600 mb-4">Tomcat是一个广泛使用的开源Java Servlet容器和Web服务器。它实现了Java EE的Servlet和JSP规范。</p>
                    <div class="bg-blue-50 p-4 rounded-lg">
                        <h4 class="font-bold text-blue-800 mb-2">优势</h4>
                        <ul class="list-disc list-inside text-blue-700 space-y-1">
                            <li>成熟稳定</li>
                            <li>广泛支持各种配置和扩展</li>
                            <li>文档丰富</li>
                        </ul>
                    </div>
                    <div class="mt-4 text-sm text-gray-500">
                        <i class="fas fa-info-circle mr-1"></i> Spring Boot默认使用Tomcat
                    </div>
                </div>

                <!-- Jetty Card -->
                <div class="card bg-white rounded-lg p-8">
                    <div class="container-icon bg-gradient-to-r from-blue-500 to-teal-400">
                        <i class="fas fa-bolt"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4">Jetty</h3>
                    <p class="text-gray-600 mb-4">Jetty是一个轻量级的开源Java Web服务器和Servlet容器。它设计用于高性能和高度可扩展的应用程序。</p>
                    <div class="bg-blue-50 p-4 rounded-lg">
                        <h4 class="font-bold text-blue-800 mb-2">优势</h4>
                        <ul class="list-disc list-inside text-blue-700 space-y-1">
                            <li>轻量级</li>
                            <li>适用于高负载和高并发场景</li>
                            <li>支持异步处理</li>
                        </ul>
                    </div>
                </div>

                <!-- Undertow Card -->
                <div class="card bg-white rounded-lg p-8">
                    <div class="container-icon bg-gradient-to-r from-purple-500 to-pink-500">
                        <i class="fas fa-tachometer-alt"></i>
                    </div>
                    <h3 class="text-2xl font-bold mb-4">Undertow</h3>
                    <p class="text-gray-600 mb-4">Undertow是一个高性能的Java Web服务器和Servlet容器，设计用于灵活性和高性能。</p>
                    <div class="bg-blue-50 p-4 rounded-lg">
                        <h4 class="font-bold text-blue-800 mb-2">优势</h4>
                        <ul class="list-disc list-inside text-blue-700 space-y-1">
                            <li>支持非阻塞I/O</li>
                            <li>适合高并发环境</li>
                            <li>内存占用少</li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Configuration Section -->
    <section class="py-16 bg-gray-100">
        <div class="container mx-auto px-6">
            <h2 class="text-3xl font-bold text-center mb-12">如何选择和配置内嵌Web容器</h2>
            
            <div class="max-w-4xl mx-auto">
                <div class="mb-12">
                    <h3 class="text-2xl font-bold mb-6 border-b-2 border-gray-200 pb-2">默认配置</h3>
                    <p class="text-gray-700 mb-6">如果不做任何配置，Spring Boot默认使用Tomcat作为内嵌的Web容器。</p>
                    
                    <div class="bg-white rounded-lg p-6 shadow-sm">
                        <div class="flex items-center mb-4">
                            <div class="w-3 h-3 bg-red-500 rounded-full mr-2"></div>
                            <div class="w-3 h-3 bg-yellow-500 rounded-full mr-2"></div>
                            <div class="w-3 h-3 bg-green-500 rounded-full"></div>
                        </div>
                        <div class="code-block">
                            <pre><code class="xml"><span class="tag">&lt;dependency&gt;</span>
    <span class="tag">&lt;groupId&gt;</span>org.springframework.boot<span class="tag">&lt;/groupId&gt;</span>
    <span class="tag">&lt;artifactId&gt;</span>spring-boot-starter-web<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;/dependency&gt;</span></code></pre>
                        </div>
                    </div>
                </div>

                <div class="mb-12">
                    <h3 class="text-2xl font-bold mb-6 border-b-2 border-gray-200 pb-2">切换容器</h3>
                    <p class="text-gray-700 mb-6">如果需要使用Jetty或Undertow，可以通过添加相应的依赖项和排除默认容器来实现。</p>
                    
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                        <!-- Jetty Configuration -->
                        <div class="card bg-white rounded-lg p-6">
                            <div class="flex items-center mb-4">
                                <div class="w-10 h-10 bg-blue-500 rounded-full flex items-center justify-center text-white mr-3">
                                    <i class="fas fa-bolt"></i>
                                </div>
                                <h4 class="text-xl font-bold">Jetty 配置</h4>
                            </div>
                            <div class="code-block">
                                <pre><code class="xml"><span class="tag">&lt;dependency&gt;</span>
    <span class="tag">&lt;groupId&gt;</span>org.springframework.boot<span class="tag">&lt;/groupId&gt;</span>
    <span class="tag">&lt;artifactId&gt;</span>spring-boot-starter-web<span class="tag">&lt;/artifactId&gt;</span>
    <span class="tag">&lt;exclusions&gt;</span>
        <span class="tag">&lt;exclusion&gt;</span>
            <span class="tag">&lt;groupId&gt;</span>org.springframework.boot<span class="tag">&lt;/groupId&gt;</span>
            <span class="tag">&lt;artifactId&gt;</span>spring-boot-starter-tomcat<span class="tag">&lt;/artifactId&gt;</span>
        <span class="tag">&lt;/exclusion&gt;</span>
    <span class="tag">&lt;/exclusions&gt;</span>
<span class="tag">&lt;/dependency&gt;</span>

<span class="tag">&lt;dependency&gt;</span>
    <span class="tag">&lt;groupId&gt;</span>org.springframework.boot<span class="tag">&lt;/groupId&gt;</span>
    <span class="tag">&lt;artifactId&gt;</span>spring-boot-starter-jetty<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;/dependency&gt;</span></code></pre>
                            </div>
                        </div>

                        <!-- Undertow Configuration -->
                        <div class="card bg-white rounded-lg p-6">
                            <div class="flex items-center mb-4">
                                <div class="w-10 h-10 bg-purple-500 rounded-full flex items-center justify-center text-white mr-3">
                                    <i class="fas fa-tachometer-alt"></i>
                                </div>
                                <h4 class="text-xl font-bold">Undertow 配置</h4>
                            </div>
                            <div class="code-block">
                                <pre><code class="xml"><span class="tag">&lt;dependency&gt;</span>
    <span class="tag">&lt;groupId&gt;</span>org.springframework.boot<span class="tag">&lt;/groupId&gt;</span>
    <span class="tag">&lt;artifactId&gt;</span>spring-boot-starter-web<span class="tag">&lt;/artifactId&gt;</span>
    <span class="tag">&lt;exclusions&gt;</span>
        <span class="tag">&lt;exclusion&gt;</span>
            <span class="tag">&lt;groupId&gt;</span>org.springframework.boot<span class="tag">&lt;/groupId&gt;</span>
            <span class="tag">&lt;artifactId&gt;</span>spring-boot-starter-tomcat<span class="tag">&lt;/artifactId&gt;</span>
        <span class="tag">&lt;/exclusion&gt;</span>
    <span class="tag">&lt;/exclusions&gt;</span>
<span class="tag">&lt;/dependency&gt;</span>

<span class="tag">&lt;dependency&gt;</span>
    <span class="tag">&lt;groupId&gt;</span>org.springframework.boot<span class="tag">&lt;/groupId&gt;</span>
    <span class="tag">&lt;artifactId&gt;</span>spring-boot-starter-undertow<span class="tag">&lt;/artifactId&gt;</span>
<span class="tag">&lt;/dependency&gt;</span></code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Visualization Section -->
    <section class="py-16">
        <div class="container mx-auto px-6">
            <h2 class="text-3xl font-bold text-center mb-12">容器选择决策图</h2>
            
            <div class="bg-white rounded-xl shadow-lg p-8 max-w-4xl mx-auto">
                <div class="mermaid">
                    graph TD
                    A[开始] --> B{项目需求}
                    B -->|默认配置| C[Tomcat]
                    B -->|需要轻量级| D[Jetty]
                    B -->|需要高性能| E[Undertow]
                    C --> F[成熟稳定<br>配置简单]
                    D --> G[轻量快速<br>适合微服务]
                    E --> H[高并发<br>低延迟]
                    style A fill:#4f46e5,color:#fff
                    style B fill:#10b981,color:#fff
                    style C fill:#f59e0b,color:#fff
                    style D fill:#3b82f6,color:#fff
                    style E fill:#8b5cf6,color:#fff
                    style F fill:#fef3c7,stroke:#f59e0b
                    style G fill:#dbeafe,stroke:#3b82f6
                    style H fill:#ede9fe,stroke:#8b5cf6
                </div>
            </div>
        </div>
    </section>

    <!-- Summary Section -->
    <section class="py-16 bg-gradient-to-r from-blue-50 to-purple-50">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto bg-white rounded-xl shadow-md overflow-hidden p-8">
                <h2 class="text-3xl font-bold mb-6 text-center">总结</h2>
                <div class="space-y-6">
                    <div class="flex items-start">
                        <div class="flex-shrink-0 h-10 w-10 rounded-full bg-blue-500 text-white flex items-center justify-center mr-4">
                            <i class="fas fa-check"></i>
                        </div>
                        <div>
                            <h3 class="text-xl font-semibold mb-2">选择原则</h3>
                            <p class="text-gray-700">根据项目具体需求选择合适的容器：Tomcat适合大多数传统应用，Jetty适合轻量级微服务，Undertow适合高性能高并发场景。</p>
                        </div>
                    </div>
                    <div class="flex items-start">
                        <div class="flex-shrink-0 h-10 w-10 rounded-full bg-green-500 text-white flex items-center justify-center mr-4">
                            <i class="fas fa-cogs"></i>
                        </div>
                        <div>
                            <h3 class="text-xl font-semibold mb-2">配置要点</h3>
                            <p class="text-gray-700">记住配置关键点：添加新容器依赖的同时必须排除默认Tomcat依赖，否则会导致冲突。</p>
                        </div>
                    </div>
                    <div class="flex items-start">
                        <div class="flex-shrink-0 h-10 w-10 rounded-full bg-purple-500 text-white flex items-center justify-center mr-4">
                            <i class="fas fa-lightbulb"></i>
                        </div>
                        <div>
                            <h3 class="text-xl font-semibold mb-2">性能考量</h3>
                            <p class="text-gray-700">对于资源受限环境，Jetty和Undertow通常比Tomcat有更好的内存占用和启动时间表现。</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-8">
        <div class="container mx-auto px-6 text-center">
            <div class="mb-4">
                <h3 class="text-xl font-bold">技术小馆</h3>
                <p class="text-gray-400">专业的开发者技术分享平台</p>
            </div>
            <div>
                <a href="http://www.yuque.com/jtostring" class="text-blue-300 hover:text-blue-100 transition-colors duration-200">
                    <i class="fas fa-globe mr-2"></i>http://www.yuque.com/jtostring
                </a>
            </div>
            <div class="mt-6 text-gray-500 text-sm">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>